@extends('layout.index')
@section('title','友情链接列表')
@section('content')
 <script type="text/javascript" charset="utf-8" src="/AD/ueditor.config.js"></script>
    
    
        <div class="panel panel-default">
            <div class="panel-heading">
                友情链接列表
            </div>
            
                <div class="panel-body">
                    <div class="dataTable_wrapper">
                        <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">  
                         <form action="{{url('/admin/links/index')}}" method="get">
                            <div class="row">
                                <div class="col-sm-6">
                                     
                                </div>
                            <div class="col-sm-6">
                        <div id="dataTables-example_filter" class="dataTables_filter">
                            
                        </div>
                        </form> 
                    </div>
                </div>
                 
            <div class="row"> 
                <div class="col-sm-12">
                    <table id="dataTables-example" class="table table-striped table-bordered table-hover dataTable no-footer" role="grid" aria-describedby="dataTables-example_info">
                        <tbody>
                            <tr class="gradeA odd" role="row">
                                    <td class="sorting_1">ID</td>
                                    <td>标题</td>
                                    <td class="center">链接</td>
                                    <td>删除</td>
                            </tr>
                        </tbody>
                        <tbody>
                         @foreach($links as $v)
                                <tr class="gradeA odd" role="row">
                                        <td class="sorting_1 sid">{{$v->id}}</td>
                                        <td class="center title">{{$v->title}}</td>
                                        <td class="center tit">{{$v->links}}</td>
                                        <td class="center">
                                        <a href="/admin/links/delete?id={{$v->id}}"  class="btn btn-warning btn-circle btn_delete" type="button"><i class="fa fa-times"></i>
                                        </a>
                                        <!-- <a href="/admin/links/edit?id={{$v->id}}" class="btn btn-primary btn-circle btn" type="button"><i class="fa fa-list"></i>
                                        </a> -->
                                        </td>
                                </tr>
                            @endforeach 
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="dataTables_info" id="dataTables-example_info" role="status" aria-live="polite">
                        Showing 1 to 10 of 57 entries
                    </div>
                </div>
                <div class="col-sm-8">
                    <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                              
                    </div>
                </div>
        </div>
    </div>

    
@endsection
@section('myjs')
<script type="text/javascript">

    
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $('.btn_delete').click(function(){
        var btn = $(this);
        var id = $(this).parents('tr').find('.sid').html();
        // alert(id);
        $.post('{{url("/admin/links/delete")}}',{id:id},function(data){
            con.loge(data);
       if(data == 1){
           btn.parents('tr').remove();
       }
        });

    });
 
   //*************************双击修改****************************//
    //绑定td
    $(function(){
    // 获取所有的用户名
    $(".title").dblclick(function(){
        if($(this).children().length != 0){
            return false;
        }
        // 获取原始值
        var oldValue = $(this).html();
        //创建input
        var input = $("<input type='text'>");   
        // 设置值
        
        input.attr("value",oldValue);
        // 追加
        $(this).html("").append(input);

        // 获取焦点
        input.select();

        // 为input绑定失去焦点的事件
        input.blur(function(){
            // 获取新的值 this == input
            var newValue = $(this).val();
            // 获取id
            var id = $(this).parents("tr").find("td:first").html();
            // 替换
            var td = $(this).parents("td");
            // 异步请求
            $.ajax({
                // 请求的方式
                type : "GET", 
                url : '{{url("/admin/links/update")}}',
                data : {id : id,title : newValue},
                // 执行成功之执行的毁掉函数 data返回回来的数据
                success : function(data){
                    if(data == 1){
                        // 修改成功
                        td.html(newValue);
                        $(".alert-success").html("用户名修改成功").show();
                        setInterval(function(){
                        
                            $(".alert-success").slideUp(1000);
                        },1500);
                    }else if(data == 0){
                        // 修改失败
                        td.html(oldValue);
                        $(".alert-danger").html("用户名修改失败").show();
                        setInterval(function(){
                        
                            $(".alert-danger").slideUp(1000);
                        },500);
                    }
                }
            });
        });
        
    });


    
      


});

 </script>

 @endsection